package anveshitha.servlets;

import javax.servlet.ServletException;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import anveshitha.config.AnveshithaConstants;
import anveshitha.timer.AnveshithaScheduler;

/**
 * Servlet implementation class for Servlet: AnveshithaStartupServlet
 *
 */
public class AnveshithaStartupServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;
	private static Logger log = null;


	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public AnveshithaStartupServlet() {
		super();
	}

	/* (non-Javadoc)
	 * @see javax.servlet.GenericServlet#init()
	 */
	public void init() throws ServletException {
		super.init();

		try {

			//configure the logger
			PropertyConfigurator.configure(getInitParameter("log4jProperties"));
			log = Logger.getLogger(AnveshithaStartupServlet.class);

			//load constants
			AnveshithaConstants.loadConfigData(getInitParameter("configXml"));
			
			
			//start the timer task based on the init params
			String param = getInitParameter("scheduleIndexers");
			if (param.equals("true"))
				AnveshithaScheduler.schedule();
			
		} catch (Exception e) {
			throw new ServletException("Error in startup servlet", e);//e.printStackTrace();
			//log.error("Exception: "+e.getMessage());
		}
	}
}